﻿using AjaxDropDownTest.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace AjaxDropDownTest.Controllers {
    public class HomeController : Controller {

        public JsonResult CitySelectListJson(string Origin, string Target, string Value) {
            List<SelectListItem> CityList;
            CityList = new List<SelectListItem>();

            switch (Value) { 
                case "Nederland":
                    CityList = new List<SelectListItem>() {
                        new SelectListItem() {
                            Text = "Amsterdam",
                            Value = "Amsterdam"
                        },
                        new SelectListItem() {
                            Text = "Rotterdam",
                            Value = "Rotterdam"
                        },
                        new SelectListItem() {
                            Text = "Den Haag",
                            Value = "Den Haag"
                        }
                    };
                    break;

                case "England":
                    CityList = new List<SelectListItem>() {
                        new SelectListItem() {
                            Text = "London",
                            Value = "London"
                        },
                        new SelectListItem() {
                            Text = "Manchester",
                            Value = "Manchester"
                        },
                        new SelectListItem() {
                            Text = "York",
                            Value = "York"
                        }
                    };
                    break;

                case "Deutschland":
                    CityList = new List<SelectListItem>() {
                        new SelectListItem() {
                            Text = "Berlin",
                            Value = "Berlin"
                        },
                        new SelectListItem() {
                            Text = "Bonn",
                            Value = "Bonn"
                        }
                    };
                    break;
            }

            return Json(CityList);
        }

        public ActionResult Index() {
            List<SelectListItem> CountryList;
            CountryList = new List<SelectListItem>() {
                new SelectListItem() {
                    Text = "Nederland",
                    Value = "Nederland"
                },
                new SelectListItem() {
                    Text = "England",
                    Value = "England"
                },
                new SelectListItem() {
                    Text = "Deutschland",
                    Value = "Deutschland"
                }
            };

            IndexViewModel ViewModel;
            ViewModel = new IndexViewModel() {
                CountryList = CountryList,
                CityList = new List<SelectListItem>()
            };

            return View(ViewModel);
        }
    }
}
